		TITLE	PACK0 - Copyright (c) SLR Systems 1994

		INCLUDE	MACROS

if	fg_prot

		PUBLIC	PACK_ZERO


		.DATA

		EXTERNDEF	EXETABLE:DWORD


		.CODE	PASS2_TEXT

		EXTERNDEF	CONVERT_SUBBX_TO_EAX:PROC,RELEASE_BLOCK:PROC


PACK_ZERO	PROC
		;
		;SCAN BACKWARDS LOOKING FOR FIRST NON-ZERO DATA
		;
		PUSH	EDI
		ADD	EDX,3

		PUSH	EBX
		AND	EDX,0FFFFFFFCH		;FIRST DWORD TO CHECK

		MOV	EDI,EDX

		SHR	EDX,PAGE_BITS
		AND	EDI,PAGE_SIZE-1

		LEA	EBX,EXETABLE[EDX*4]
		;
		;FIRST CHECK PARTIAL LAST BLOCK
		;
		JZ	L5$			;OOPS, NO PARTIAL BLOCK

		CALL	CONVERT_SUBBX_TO_EAX

		MOV	ECX,EDI
		LEA	EDI,[EDI+EAX-4]

		SHR	ECX,2
		XOR	EAX,EAX

		STD

		REPE	SCASD

		CLD

		JNZ	L7$			;NON-ZERO DATA, HELP ME
L2$:
		;
		;TRY ANOTHER COMPLETE BLOCK
		;
		XOR	ECX,ECX
		MOV	EAX,[EBX]

		MOV	[EBX],ECX
		CALL	RELEASE_BLOCK
L5$:
		DEC	EDX
		JS	L6$			;OOPS, DONE!

		MOV	EAX,[EBX-4]
		SUB	EBX,4

		TEST	EAX,EAX
		JZ	L5$

		LEA	EDI,[EAX+PAGE_SIZE-4]
		MOV	ECX,PAGE_SIZE/4

		XOR	EAX,EAX

		STD

		REPE	SCASD

		CLD

		JZ	L2$

		JMP	L7$

L6$:
		XOR	EDX,EDX
		JMP	L9$

L7$:
		;
		;NON-ZERO STUFF HERE (NORMAL...)
		;
		MOV	AL,[EDI+7]
		LEA	EDI,[EDI+6]

		OR	AL,AL
		JNZ	L71$

		MOV	AL,[EDI]
		DEC	EDI

		OR	AL,AL
		JNZ	L71$

		MOV	AL,[EDI]
		DEC	EDI

		OR	AL,AL
		JNZ	L71$

		DEC	EDI
L71$:
		ADD	EDI,2
		MOV	EAX,[EBX]

		SUB	EDI,EAX			;OFFSET FROM BLOCK
		;
		;
		;
		CMP	EDI,PAGE_SIZE
		JNZ	L74$

		XOR	EDI,EDI
		INC	EDX
L74$:
		SHL	EDX,PAGE_BITS

		OR	EDX,EDI
L9$:
		POPM	EBX,EDI

		RET

PACK_ZERO	ENDP

endif

		END

